package weeek2;

public
class Dome1 {
    static int ticket=100;
    public static
    void main(String[] args) {
        new Thread(()->{
            a();
        },"窗口一").start();
        new Thread(()->{
            a();
        },"窗口二").start();
        new Thread(()->{
            a();
        },"窗口三").start();
    }
    public static  void a(){
        String name=Thread.currentThread().getName();
            while (ticket>0){
                synchronized (Dome1.class) {
                    if(ticket!=0) {
                        System.out.println(name + "卖出第" + (101 - ticket) + "张票");
                        ticket--;
                        try {
                            Thread.sleep(100);
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                    }
                }
            }
    }
}
